﻿namespace Xmart.Expressions.DynamicPredicate;

public class DynamicPredicateItem
{
    private string _Property = string.Empty;
    /// <summary>
    /// 条件属性
    /// </summary>
    public string Property
    {
        get
        {
            return _Property;
        }
        set
        {
            if (value.Contains("#"))
            {
                var sp = value.Split('#');
                if (sp.Length >= 3)
                {
                    _Property = sp[0];
                    AggregateGroupName = sp[1];
                    if (sp.Length == 3)
                    {
                        if (sp[2].EndsWith("()"))
                        {
                            AggregateType = Enum.Parse<AggregateType>(sp[2][..^2]);
                        }
                        else
                        {
                            AggregateProperty = sp[2];
                        }
                    }
                    else
                    {
                        AggregateType = Enum.Parse<AggregateType>(sp[2][..^2]);
                        AggregateProperty = sp[3];
                    }
                }
                else
                {
                    _Property = value;
                }
            }
            else
            {
                _Property = value;
            }
        }
    }
    /// <summary>
    /// 条件比较方式
    /// </summary>
    public CompareType CompareType { get; set; }
    /// <summary>
    /// 子项聚合组名
    /// </summary>
    public string AggregateGroupName { get; set; } = string.Empty;
    /// <summary>
    /// 子项聚合方式
    /// </summary>
    public AggregateType? AggregateType { get; set; }
    /// <summary>
    /// 子项聚合属性
    /// </summary>
    public string AggregateProperty { get; set; } = string.Empty;
    /// <summary>
    /// 条件值
    /// </summary>
    public string Value { get; set; } = string.Empty;
    /// <summary>
    /// 条件项，用于复杂子项条件满足处理
    /// </summary>
    public DynamicPredicateModel? ItemPredicateModel { get; set; }
    /// <summary>
    /// 自定义比较方式
    /// </summary>
    public string? CustomCompareType { get; set; }
}
